﻿Imports System.Data.SqlClient

Public Class AVenir

    Private user As String
    Private userSite As String
    Private cn As CnData
    Private da As SqlDataAdapter
    Private ds As DataSet
    Private cmd As SqlCommand
    Private dtr As SqlDataReader

    Public Sub New(ByVal user As String, ByRef cn As CnData, ByVal userSite As String)
        ' Cet appel est requis par le concepteur.
        InitializeComponent()

        ' Ajoutez une initialisation quelconque après l'appel InitializeComponent().
        Me.user = user
        Me.cn = cn
        Me.userSite = userSite

    End Sub

    Private Sub AVenir_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        cn.Open()
        cmd = New SqlCommand("SELECT NomDoc FROM Sites WHERE NumSite='" & userSite & "'", cn.getCn)
        SiteD.Text = cmd.ExecuteScalar
        da = New SqlDataAdapter("SELECT     Chargements.Chargement AS [N° Chargement], Sites.nomDoc AS [Site expéditeur], Chargements.DateExp AS [Date expédition], " _
                    & "Chargements.HeureExp AS [Heure expédition], Chargements.Statut AS [Statut chargement], Chargements.NbAgres AS [Nombre d'agrès] " _
                    & "FROM         Chargements LEFT OUTER JOIN " _
                    & "Sites ON Chargements.Expediteur = Sites.NumSite WHERE Destinataire='" & userSite & "' AND Statut='Transit'", cn.getCn)
        da.Fill(ChargDT)
        ListeLP.DataSource = ChargDT

        Cpt.Text = ChargDT.Rows.Count
        cn.Close()
    End Sub


    Private Sub ListeLP_CellContentDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles ListeLP.CellContentDoubleClick
        If e.RowIndex >= 0 Then
            Dim ChildForm As New Reception(user, cn, userSite, ListeLP.Rows(e.RowIndex).Cells(0).Value.ToString, False)
            ChildForm.ShowDialog()
            ChargDT.Clear()
            da = New SqlDataAdapter("SELECT     Chargements.Chargement AS [N° Chargement], Sites.nomDoc AS [Site expéditeur], Chargements.DateExp AS [Date expédition], " _
                    & "Chargements.HeureExp AS [Heure expédition], Chargements.Statut AS [Statut chargement], Chargements.NbAgres AS [Nombre d'agrès] " _
                    & "FROM         Chargements LEFT OUTER JOIN " _
                    & "Sites ON Chargements.Expediteur = Sites.NumSite WHERE Destinataire='" & userSite & "' AND Statut='Transit'", cn.getCn)
            da.Fill(ChargDT)
            ListeLP.DataSource = ChargDT

            Cpt.Text = ChargDT.Rows.Count
        End If
    End Sub

    Private Sub Fermer_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Fermer.Click
        Me.Close()
    End Sub
End Class